﻿Namespace Shows
	<Serializable()> Public Class RecentShowsList

		Public Property Project1 As String = ""
		Public Property Project2 As String = ""
		Public Property Project3 As String = ""
		Public Property Project4 As String = ""

		Public ReadOnly Property Items As List(Of String)
			Get
				Dim l As New List(Of String)
				l.Add(Project1)
				l.Add(Project2)
				l.Add(Project3)
				l.Add(Project4)
				Return l
			End Get
		End Property

		Public Sub AddProject(ByVal PL As String)
			If PL = Project1 Then
				'Return
			ElseIf PL = Project2 Then
				Project2 = Project1
				Project1 = PL
				'Return
			ElseIf PL = Project3 Then
				Project3 = Project2
				Project2 = Project1
				Project1 = PL
				'Return
			Else
				Project4 = Project3
				Project3 = Project2
				Project2 = Project1
				Project1 = PL
				'Return
			End If
			PrepProjects()
		End Sub

		''' <summary>
		''' Checks to make sure that all the projects in the list exist and removes them if they don't.
		''' </summary>
		''' <remarks></remarks>
		Private Sub PrepProjects()
			Try
				If Not FileIO.FileSystem.FileExists(Project1) Then
					Project1 = ""
				End If
			Catch
			End Try
			Try
				If Not FileIO.FileSystem.FileExists(Project2) Then
					Project2 = ""
				End If
			Catch
			End Try
			Try
				If Not FileIO.FileSystem.FileExists(Project3) Then
					Project3 = ""
				End If
			Catch
			End Try
			Try
				If Not FileIO.FileSystem.FileExists(Project4) Then
					Project4 = ""
				End If
			Catch
			End Try
			If Project1 = "" Then
				If Project2 <> "" Then
					Project1 = Project2
				ElseIf Project3 <> "" Then
					Project1 = Project3
				ElseIf Project4 <> "" Then
					Project1 = Project4
				End If
			End If
			If Project2 = "" Then
				If Project3 <> "" Then
					Project2 = Project3
				ElseIf Project4 <> "" Then
					Project2 = Project4
				End If
			End If
			If Project3 = "" Then
				If Project4 <> "" Then
					Project3 = Project4
				End If
			End If
		End Sub

		''' <summary>
		''' Retrieves a MenuItem with the appropriate information added to allow for opening recent projects.
		''' </summary>
		''' <param name="i"></param>
		''' <returns></returns>
		''' <remarks></remarks>
		<Obsolete("This function is no longer used.", True)> Public Function GetMenuItem(ByVal i As Integer) As MenuItem
			PrepProjects()
			Dim m As New MenuItem

			Select Case i
				Case 1
					If Project1 = "" Then Return Nothing
					If Project1.Length > 35 Then
						m.Header = "..." & Project1.Substring(Project1.Length - 35)
					Else
						m.Header = Project1
					End If
					m.Tag = Project1
				Case 2
					If Project2 = "" Then Return Nothing
					If Project2.Length > 35 Then
						m.Header = "..." & Project2.Substring(Project2.Length - 35)
					Else
						m.Header = Project2
					End If
					m.Tag = Project2
				Case 3
					If Project3 = "" Then Return Nothing
					If Project3.Length > 35 Then
						m.Header = "..." & Project3.Substring(Project3.Length - 35)
					Else
						m.Header = Project3
					End If
					m.Tag = Project3
				Case 4
					If Project4 = "" Then Return Nothing
					If Project4.Length > 35 Then
						m.Header = "..." & Project4.Substring(Project4.Length - 35)
					Else
						m.Header = Project4
					End If
					m.Tag = Project4
			End Select

			Return m
		End Function

	End Class

End Namespace